package com.ftg.learn.chapter08;

public class Demo2 {

    public void yi(){
        int x = 1;
        int y = 2;
        int t = 0;
        t = y;
        y = x;
        x = t;
        System.out.println(x+" "+y);

        x = 1;
        y = 2;
        x = y+x;
        y = x-y;
        x = x-y;
        System.out.println(x+" "+y);
    }

    /**
     *  1 2 3 4 5 6 7 梅花桩
     */
    public void er(){
        int sum = 1;
        boolean b = true;
        for(int i = 1;i<=30;i++){
            if(b){
                if(sum==7){
                    b = false;
                    sum--;
                }else{
                    sum++;
                }
            }else {
                if(sum == 1){
                    b =true;
                    sum++;
                }else {
                    sum--;
                }
            }
            System.out.println("第"+i+"跳，第"+sum+"石头");
        }
    }


    public void san(){
        for(int i =1,hang = 10;i<hang;i++){
            for(int j =1,lie = 10;j<lie;j++){
                if(i<=lie/2){
                    if(j<=i){
                        System.out.print(j+"\t");
                    }else if(j>lie-i){
                        System.out.print(lie-j+"\t");
                    }else{
                        System.out.print(i+"\t");
                    }
                }else{
                    if(j<lie+1-i){
                        System.out.print(j+"\t");
                    }else if(j>i){
                        System.out.print(lie-j+"\t");
                    }else{
                        System.out.print(lie-i+"\t");
                    }
                }
            }
            System.out.println();
        }
    }
    public void si(int hang){
        for(int i = 1;i<=hang;i++){
            for(int j = 1;j<=i;j++){
                System.out.print(j+"*"+i+"="+i*j+"\t");
            }
            System.out.println();
        }
    }


    public  void wu() {
        //素数，能被1和自身整除的数
        //如果要求200以内的质数 将100改为两百即可
        for (int i = 2; i < 100; i++) {
            boolean zhishu = true;
            //每个数除以它之前的数，是否能整出
            for (int j = 2; j < i ; j++) {
                if (i % j == 0 && i!=2) {
                    zhishu = false;
                    break;//可以省去，但是效率会下降
                }
            }
            if (zhishu) {
                System.out.println(i);
            }
        }
    }
    //素数的算法优化版
    public void liu(){
        for(int i = 2;i < 100;i++){
            boolean b = true;
            for(int j = 2;j<=Math.sqrt(i);j++){
                if(i%j==0 && i!=2){
                    b = false;

                }
            }
            if(b){
                System.out.println(i);
            }

        }
    }

}
